import { onMounted, ref } from "vue"
import { getTopCategoryAPI } from '@/apis/layout';
import { onBeforeRouteUpdate, useRoute } from 'vue-router';


export function useCategory() {
  const route = useRoute()
  const categoryData = ref({})
  const getTopCategory = async (id = route.params.id) => {
    // console.log(route.params.id)
    const res = await getTopCategoryAPI(id)
    categoryData.value = res.result
  }

  onMounted(() => {
    getTopCategory()
  })
  onBeforeRouteUpdate((to) => {
    getTopCategory(to.params.id)
  })
  return { categoryData }
}
